package com.hongyi.service.Impl;

import com.hongyi.mapper.StudentMapper;
import com.hongyi.pojo.PageBean;
import com.hongyi.pojo.Student;
import com.hongyi.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author hongyi
 * @date 2023/11/25 11:00
 */
@Service
public  class StudentMapperImpl implements StudentService {

    @Autowired
    private StudentMapper studentMapper;
    @Override
    public void add(Student student) {
        studentMapper.add(student);
    }

    @Override
    public void update(Student student) {
            studentMapper.update(student);
    }

    @Override
    public void delete(Integer id) {
         studentMapper.delete(id);
    }


    /**
     * 业务功能需要写一下
     * 总的来说属于分页的业务功能
     *
     * @param name        查询条件
     * @param sex         查询条件
     * @param currentPage 当前页
     * @param pageSize    每页
     * @return
     */
    @Override
    public PageBean<Student> selectPage(String name, String sex, int currentPage, int pageSize) {
        // 当前页
        int begin = (currentPage - 1) * pageSize;
        // 每页存放的条数
        int size = pageSize;

        // 查询当前页的内容
        List<Student> rows = studentMapper.selectPage(name, sex, begin, size);

        // 当前页的条数
        int selectCount = studentMapper.selectCount(name,sex);

        // 封装Page
        PageBean<Student> pageBean = new PageBean<>();
        pageBean.setTotalCount(selectCount);
        pageBean.setRows(rows);
        //
        return pageBean;
    }

    @Override
    public Student finById(Integer id) {
        return studentMapper.finById(id);
    }
}
